package com.youtellv1.mapper;

import com.youtellv1.entity.Post;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PostMapper extends BaseMapper<Post>{

    @Select("select * from tb_post order by pid limit #{offset}, #{limit}")
    List<Post> findAllPost(@Param("offset") int offset, @Param("limit") int limit);

    @Select("select * from tb_post where pid = #{pid}")
    Post findPostById(Post post);

    @Insert("insert into tb_post(pname, post_sal) values (#{pname}, #{post_sal})")
    void save(Post post);

    @Select("select * from tb_post")
    List<Post> findAll();

    @Update("<script>" +
            "update tb_post " +
            "<set>" +
            "    <if test='pname != null'>pname = #{pname},</if>" +
            "    <if test='post_sal != null'>post_sal = #{post_sal}</if>" +
            "</set>" +
            "where pid = #{pid}" +
            "</script>")
    void update(Post post);

    @Delete("delete from tb_post where pid = #{pid}")
    void delete(Post post);

    @Select("select count(*) from tb_post")
    Integer postCount();
}
